package com.zhj.edu.exception.notify.observer.impl;

import com.zhj.edu.exception.notify.observer.base.Observer;
import com.zhj.edu.exception.notify.observer.base.Subject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SubjectImpl implements Subject {

    /**
     * 注入，使该类能调用EmailObserver和SmsObserver
     */
    @Autowired
    private List<Observer> observers;

    @Override
    public void notifyMessage(String msg) {
        for (int i = 0; i < observers.size(); i++) {
            Observer observer = observers.get(i);//依赖倒置
            observer.notifyMessage(msg);
        }
    }
}
